package com.darrenchan.leetcode;

/**
 * @Desc
 * @Author chenchi03
 * @CreateTime 2019-12-29 22:30
 */
public class Q367 {
    public boolean isPerfectSquare(int num) {
        if(num == 1) {
            return true;
        }
        long start = 0, end = num / 2;
        while (start + 1 < end) {
            long mid = start + (end - start) / 2;
            if (mid * mid < num) {
                start = mid;
            } else {
                end = mid;
            }
        }

        if (start * start == num || end * end == num) {
            return true;
        }
        return false;
    }

    public static void main(String[] args) {
        System.out.println(new Q367().isPerfectSquare(808201));
    }
}
